package com.weeego.util.string;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Reg {

	// Replace the no use space

	public static String replaceReg(String stringInfo) {

		Pattern p = Pattern.compile(" {2,}");// 去除多余空格

		Matcher m = p.matcher(stringInfo);

		return m.replaceAll(" ");

	}

	/**
	 * 将字符串中的 跟正则表达式 reg匹配的字段替换成空格
	 * 
	 * @param stringInfo
	 * @param reg
	 * @return
	 */
	public static String replaceReg(String stringInfo, String reg) {

		// String stringInfo =
		// "{infoNum='10' EdwardBlog='http://hi.baidu.com/Edwardworld'       topicLength='20'    titleShow='yes' EdwardMotto='I am a man,I am a true man!' /}";

		// System.out.println("待处理的字符串：" + stringInfo);

		// Pattern p = Pattern.compile("[.,\"\\?!:']");// 增加对应的标点

		// Matcher m = p.matcher(stringInfo);

		// String first = m.replaceAll(""); // 把英文标点符号替换成空，即去掉英文标点符号

		// System.out.println("去掉英文标点符号后的字符串：" + first);

		Pattern p = Pattern.compile(reg);

		Matcher m = p.matcher(stringInfo);

		return m.replaceAll(" ");

	}

	public static void main(String[] args) {
		System.out.print(Reg.replaceReg("asdasda sdas       "
				+ "   asd ,asd ,asd,asd, asd,asd ," + "asd ,asd ,asd "));

		System.out.print(Reg.replaceReg("asdasda sdas       "
				+ "   asd ,,,,,, ,,,, ,, , , , ,,asd ,asd,asd, asd,asd ,"
				+ "asd ,asd ,asd ", ",{2,}"));

	}
}
